//2009/07/31 12:16:36
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>

using namespace std;

class Sets
{
public:
    vector <int> operate(vector <int> A, vector <int> B, string operation)
    {
        vector<int> v1;
        v1.clear();
        vector<int> v2(A);
		//Intersection;
        for (int i=0; i<A.size(); i++)
        {
            for (int j=0; j<B.size(); j++)
            {
                if (A[i] == B[j])
                {
                    v1.push_back(A[i]);
                    break;
                }
            }
        }
		//Union;
		for(int i=0; i<B.size(); i++)
		{
			bool flag = true;
			for(int j=0; j<A.size(); j++)
			{
				if(A[j] == B[i])
					flag = false;
			}
			if(flag)
				v2.push_back(B[i]);
		}
		//Symmetric Difference;
		vector<int> v3(v2);
		for(int i=0; i<v1.size(); i++)
		{
			for(int j=0; j<v3.size(); j++)
			{
				if(v1[i] == v3[j])
				{
					v3.erase(v3.begin() + j);
					break;
				}
			}
		}
		sort(v1.begin(), v1.end());
		sort(v2.begin(), v2.end());
		sort(v3.begin(), v3.end());
        if (operation.compare("INTERSECTION") == 0)
        {
            return v1;
        }
        if (operation.compare("UNION") == 0)
        {
            return v2;
        }
        else if (operation.compare("SYMMETRIC DIFFERENCE") == 0)
        {
            return v3;
        }
    }
};
